<!-- 使用ts和泛型接收asiox返回值 -->
<template>
  <div>
    <h2>用户列表</h2>
    <ul>
      <li v-for="user in users" :key="user.id">
        {{ user.name }} - {{ user.email }}
      </li>
    </ul>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import _axios from '@/api/request'
import type { User } from '@/model'

const users = ref<User[]>([])

const fetchUsers = async () => {
  try {
    const response = await _axios.get<User[]>('/user')
    users.value = response.data
  } catch (error) {
    console.error('获取用户失败:', error)
  }
}

onMounted(() => {
  fetchUsers()
})
</script>
